package cn.co.Servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "RequestForwardServlet",urlPatterns = "/RequestForwardServlet")
public class RequestForwardServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //下面三行是网上找的PrintWriter输出中文乱码的解决办法
        resp.setHeader("content-type", "text/html;charset=UTF-8");
        //用HttpServletRequest对象的getParameter()方法获取用户名
        String username=req.getParameter("username1");
        req.setAttribute("username",username);//将数据存储到request对象中
        RequestDispatcher dispatcher = req.getRequestDispatcher("/ResultServlet");
        dispatcher.forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
